feat: add per-head fp8 kv attention calibration - #2044
Conversation
|
/azp run Unit-Test-CUDA-AutoRound |
|
Commenter does not have sufficient privileges for PR 2044 in repo intel/auto-round |
43cd2cb to
d2d95fb
Compare
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hi @zeel2104, thanks for the contribution! Overall, it looks good to me. Could you please rebase the changes onto the latest main branch and resolve the CI issues? We also need to quantize the model and validate inference in vLLM using the Triton backend. |
|
Hi @zeel2104, are you still working on this PR? We're targeting this feature for the current release. If you're tied up with other work, please let me know. Thanks! |
Signed-off-by: Zeel <desaizeel2128@gmail.com>
bfc6e01 to
4b672fc
Compare
|
Hi @yiliu30, sorry for late reply. I rebased this PR onto the latest I also resolved the LLMC exporter conflict by keeping the newer top-level Local validation after rebase:
I do not have vLLM/Triton available locally, so I’ll need CI or a CUDA environment for the vLLM Triton inference validation. |
There was a problem hiding this comment.
Findings
- [P1] auto_round/experimental/utils.py:69: The new per-head FP8 QDQ path casts directly through
torch.float8_e4m3fninstead of using the project’s STE helper. Tensor granularity usesfloat8_e4m3fn_ste()inauto_round/data_type/fp8.py, which preserves gradient flow during optimized calibration. Withstatic_*_granularity="head"anditers > 0, this new path can cut or mishandle gradients through Q/K/V, so per-head mode is not equivalent to the existing static FP8 behavior. Please route the per-head cast through the same STE helper and add a gradient-flow test.
Hi @zeel2104 it is fine, could you quantize the Qwen3-8B and upload it the hugging face. I can help verify it. |
…attn # Conflicts: # auto_round/autoround.py # auto_round/compressors/entry.py # test/test_cpu/export/test_export.py # test/test_cpu/export/test_llmc_format.py
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| "--static_kv_granularity", | ||
| default="tensor", | ||
| type=str, | ||
| choices=["tensor", "head"], |
There was a problem hiding this comment.
We already have too many CLI arguments. Is there a way to group all the KV-related options into a kv_scheme and provide some predefined presets to cover the common use cases?
There was a problem hiding this comment.
Yes, I’m also thinking about refining the KV-cache and attention quantization configs into dedicated schemes, something like:
"kv_cache_scheme": {
"dynamic": false,
"group_size": null,
"num_bits": 8,
"strategy": "tensor"
...
}I’ll prepare an RFC for this later. For this PR, though, I think the current functionality looks good.
| self.is_immediate_saving = is_immediate_saving | ||
| self.static_kv_dtype = static_kv_dtype | ||
| self.static_attention_dtype = static_attention_dtype | ||
| self.static_kv_granularity = static_kv_granularity |
There was a problem hiding this comment.
Personally, I think KV-related options belong in the scheme context rather than the compression context.
@n1ck-guo, could you refine the definition of each context and clearly explain its purpose? That would make it much easier for developers to understand which context a new option should belong to.
686cb08 to
ec402e6
Compare
…attn # Conflicts: # test/unit/test_cpu/test_experimental_fp8_granularity.py
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
for more information, see https://pre-commit.ci
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Resolve #2026
Description
Adds per-head FP8 KV/attention calibration support on top of the existing per-tensor static FP8 paths.
Main changes:
static_kv_granularityandstatic_attention_granularityoptions with"tensor"as the default and"head"as the new per-head mode.k_scale,v_scale, andq_scalefor attention tensors shaped as[batch, heads, seq, head_dim].attn_headstrategy for per-head KV/attention scales.safe_openhandles before reusing the output path.Type of Change
New feature
Related Issues
Relates to #2026
Checklist Before Submitting
/azp run Unit-Test-CUDA-AutoRound.Tested locally:
python -m pytest test/test_cpu/test_experimental_fp8_granularity.py -qpython -m pytest test/test_cpu/export/test_llmc_format.py -qpython -m pytest test/test_cpu/export/test_export.py -k "per_head or static_afp8_export or static_fp8_attn" -qpython -m pytest test/test_cpu/quantization/test_mxfp_nvfp.py -k "fp8_kv_attn" -qNote:
test/test_cpu/integrations/test_inc_integration.pywas not run becauseneural_compressoris not installed locally.